<template>
	<view class="content">
		<view class="con1">
			<view class="item" v-for="(item, index) in serviceList" :key="index">
				<view class="left">
					<image class="icon-image" :src="rq.imgUrl(item.image)" mode=""></image>
				</view>
				<view class="right">
					<view class="r1">
						<view class="name">
							{{ item.name }}
						</view>
						<view class="btn">
							<image @click="goPage('service', item.id)" class="btn1"
								src="https://pw.qyang.cc/static/icon-edit.png" mode=""></image>
							<switch color="#84E28D" :checked="item.is_open == 1" style="transform:scale(0.6)"
								@change="setServiceChange(item)" @click="setService(item)" :disabled="item.price*1==0&&item.is_open==0"/>
						</view>
					</view>
					<view class="r2">
						<view class="text">
							默认：<span class="num">{{ item.price }} 元</span>
						</view>
						<view class="text">
							最低：<span class="num">{{ item.low }} 元</span>
						</view>
						<view class="text">
							起始：<span class="num">{{ item.starting }}小时</span>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tablist: [],
				model: {},
				current: 0,
				page: 1,
				serviceList: [],
				city_id: null,
				total:0
			};
		},
		onPullDownRefresh() {
			this.page = 1;
			uni.hideNavigationBarLoading();
			this.getService()
		},
		onReachBottom() {
			if (this.serviceList.length < this.total) {
				this.getService(true)
				this.page++;
			}
		},
		onLoad(e) {
			this.city_id = e.city_id			
		},
		onShow() {
			this.getService()
		},
		methods: {
			// 获取服务列表
			getService(more) {
				this.rq.getData('Service/index', { page: this.page,city_id:this.city_id }).then(res => {
					this.total = res.data.total
					if (more) {
						this.serviceList = this.serviceList.concat(res.data.data)
					} else {
						this.serviceList = res.data.data
					}
					uni.stopPullDownRefresh()
				}).catch(()=>{
					uni.stopPullDownRefresh()
				})
			},
			// 城市切换
			click(e) {
				this.city_id = e.id
				this.rq.getData('Agency_Config/index', { city_id: e.id }).then(res => {
					this.model = res.data
				})
			},
			// 服务开关
			setServiceChange(item,index) {
				if(item.price*1>0){
					this.rq.getData('Service_Area/open', { id: item.id, is_open: item.is_open == 1 ? 0 : 1, city_id: this.city_id }).then(res => {
						
					})
				}				
			},
			setService(item){
				if(item.price*1==0&&item.is_open==0){
					uni.showToast({
						title:'请设置服务金额后开启~',
						icon:'none'
					})
				}
			},
			// 跳转
			goPage(url, id) {
				if (url == 'service') {
					uni.navigateTo({
						url: `/subpages/proxyManage/${url}?id=${id}&city_id=${this.city_id}`
					})
				}	
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		margin-top: 20rpx;
		width: 100%;
		.con1 {
			margin: 24rpx;
			background: #fff;
			border-radius: 20rpx;
			padding: 0 20rpx 20rpx;
		
			.item {
				padding-top: 20rpx;
				display: flex;
				align-items: center;
		
				.left {
		
					.icon-image {
						width: 66rpx;
						height: 66rpx;
					}
				}
		
				.right {
					width: 100%;
					margin-left: 20rpx;
		
					.r1 {
						display: flex;
						align-items: center;
						justify-content: space-between;
						height: 50rpx;
		
						.name {
							font-family: 阿里巴巴普惠体 2.0;
							font-size: 14px;
							font-weight: normal;
							line-height: 16px;
							letter-spacing: 0px;
		
							color: #333333;
						}
		
						.btn {
							display: flex;
							align-items: center;
		
							.btn1 {
								width: 26rpx;
								height: 26rpx;
							}
						}
					}
		
					.r2 {
						display: flex;
						align-items: center;
						justify-content: space-between;
		
						.text {
							font-family: 阿里巴巴普惠体;
							font-size: 12px;
							font-weight: normal;
							line-height: 12px;
							letter-spacing: 0px;
		
							color: #999999;
		
							.num {
								font-family: 阿里巴巴普惠体;
								font-size: 12px;
								font-weight: normal;
								line-height: 12px;
								letter-spacing: 0px;
		
								color: #FF7681;
							}
						}
					}
				}
			}
		
			.text1 {
				font-family: PingFang SC;
				font-size: 14px;
				font-weight: normal;
				line-height: 14px;
				letter-spacing: 0px;
				color: #666666;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin: 20rpx 0;
		
				.input1 {
					display: flex;
					align-items: center;
		
					span {
						margin-left: 20rpx;
						color: #333333;
					}
				}
			}
		
			.text {
				font-family: PingFang SC;
				font-size: 14px;
				font-weight: normal;
				line-height: 14px;
				letter-spacing: 0px;
				color: #666666;
				display: flex;
				align-items: center;
				margin: 20rpx 0;
		
				.input {
					width: 17.95%;
					height: 21.82%;
					border-radius: 4px;
					opacity: 1;
					background: #F1F1F1;
					margin: 0 20rpx;
					text-align: center;
		
				}
			}
		}
	}
</style>